package com.macro.controller;


import com.macro.pojos.dto.ResponseResult;
import com.macro.pojos.dto.UserDto;
import com.macro.pojos.dto.UserUpdateDto;
import com.macro.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "用户注册相关接口")
public class UserController {
    @Value("${fileServerUrl}")
    private String fileServerUrl;
    @Autowired
    private UserService userService;

    /**
     * 用户注册
     * @param userDto
     * @return
     */
    @PostMapping("enroll_user")
    @ApiOperation(value = "用户注册")
    public ResponseResult enrollUser(@RequestBody UserDto userDto){
        return userService.enrollUser(userDto);
    }

    /**
     * qq邮箱发送验证码
     * @param eml
     * @return
     */
    @GetMapping("go_code")
    @ApiOperation(value = "qq邮箱发送验证码")
    public ResponseResult goCode(@RequestParam String eml){
        return userService.goCode(eml);
    }

    /**
     * 验证验证码是否正确
     * @param code
     * @return
     */
    @GetMapping("verification_code")
    @ApiOperation(value = "验证验证码是否正确")
    public ResponseResult VerificationCode(@RequestParam String code){
        return userService.VerificationCode(code);
    }

    /**
     * 头像上传
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    @ApiOperation(value = "上传头像")
    public ResponseResult upload(MultipartFile file) throws IOException {
        return userService.upload(file);
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @GetMapping("delete_user")
    @ApiOperation(value = "删除用户")
    public ResponseResult deleteUser(@RequestParam Integer id){
        return userService.deleteUser(id);
    }

    /**
     * 修改用户信息
     * @param userUpdateDto
     * @return
     */
    @GetMapping("update_user")
    @ApiOperation(value = "修改用户信息")
    public ResponseResult updateUser(@RequestBody UserUpdateDto userUpdateDto){
        return userService.updateUser(userUpdateDto);
    }


}
